package com.atguigu.tingshu.album.mapper;

import com.atguigu.tingshu.model.album.BaseCategory3;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface BaseCategory3Mapper extends BaseMapper<BaseCategory3> {

    /**
     * 根据一级分类查询置顶前七的三级分类
     * @param category1Id
     * @return
     */
    @Select("SELECT \n" +
            "  t2.`id`,\n" +
            "  t2.`name`,\n" +
            "  t2.`category2_id`,\n" +
            "  t2.`order_num`,\n" +
            "  t2.`is_top` \n" +
            "FROM\n" +
            "  base_category2 t1 \n" +
            "  LEFT JOIN base_category3 t2 \n" +
            "    ON t1.`id` = t2.`category2_id` \n" +
            "WHERE t1.`category1_id` = #{category1Id} \n" +
            "  AND t1.`is_deleted` = 0 \n" +
            "  AND t2.`is_deleted` = 0 \n" +
            "ORDER BY t2.`is_top` \n" +
            "LIMIT 7 ")
    List<BaseCategory3> findTopBaseCategory3(Long category1Id);
}
